Imports System.Security.Cryptography
Imports System.Text

Namespace DPRAjaxControlToolkit

    Public Class RSACrypto
        Private _sp As RSACryptoServiceProvider

        Public Function ExportParameters(ByVal includePrivateParameters As Boolean) As RSAParameters
            Return _sp.ExportParameters(includePrivateParameters)
        End Function

        Public Sub New(ByVal sp As RSACryptoServiceProvider)
            _sp = sp
        End Sub

        Public Function Encrypt(ByVal texto As String) As Byte()
            Dim retorno As Byte()

            Dim enc As New ASCIIEncoding()
            Dim numOfChars As Integer = enc.GetByteCount(texto)
            Dim tempArray As Byte() = enc.GetBytes(texto)
            retorno = _sp.Encrypt(tempArray, False)

            Return retorno

        End Function

        Public Function Decrypt(ByVal dados As Byte()) As Byte()
            Dim retorno As Byte()

            retorno = _sp.Decrypt(dados, False)

            Return retorno
        End Function
    End Class

End Namespace
